//
//  DeviceSetListViewController.m
//  Lightthings
//
//  Created by Hero on 2024/11/16.
//

#import "DeviceSetListViewController.h"

@interface DeviceSetListViewController ()
@property (nonatomic, strong) NSString * uuid;
@end

@implementation DeviceSetListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.collectionInsets = kEdge(self.jy_bar_h, 0, 0, 0    );
    
    self.uuid = self.metaInfo[@"uuid"];
  
    
    [self initData];
    // Do any additional setup after loading the view.
}

- (void)initData {
    
    MainSectionModel * s = [[MainSectionModel alloc] init];
    
    if ([self.metaInfo[@"type"] isEqualToString:@"watch"]) {
        
        self.jy_title = SWString(@"监控");
        
        [s.items addObject:[self cModelWithTitle:SWString(@"表盘设置") Image:@"表盘切换" Action:Command_DialSwitch]];
        [s.items addObject:[self cModelWithTitle:SWString(@"亮屏时间") Image:@"亮度调节" Action:Command_ScreenTime]];
        [s.items addObject:[self cModelWithTitle:SWString(@"振动设置") Image:@"振动设置" Action:Command_VibrationSet]];
        [s.items addObject:[self cModelWithTitle:SWString(@"抬腕亮屏") Image:@"抬腕亮屏" Action:Command_RaiseHand]];
        [s.items addObject:[self cModelWithTitle:SWString(@"12/24小时设置") Image:@"24小时设置" Action:Command_12_24_Set]];
        [s.items addObject:[self cModelWithTitle:SWString(@"语言设置") Image:@"语言选择" Action:Command_LanguageSet]];
        [s.items addObject:[self cModelWithTitle:SWString(@"公英制设置") Image:@"公英制设置" Action:Command_LengthSet]];
        [s.items addObject:[self cModelWithTitle:SWString(@"温度单位设置") Image:@"温度单位设置" Action:Command_TemperatureSet]];
    }else if ([self.metaInfo[@"type"] isEqualToString:@"health"]) {
        self.jy_title = SWString(@"健康数据设置");
        [s.items addObject:[self cModelWithTitle:SWString(@"计步目标") Image:@"计步目标" Action:Command_StepGoal]];
        [s.items addObject:[self cModelWithTitle:SWString(@"定时心率提醒") Image:@"定时心率提醒" Action:Command_HeartRateReminders]];
        [s.items addObject:[self cModelWithTitle:SWString(@"久坐提醒") Image:@"久坐提醒" Action:Command_Sedentary]];
        [s.items addObject:[self cModelWithTitle:SWString(@"喝水提醒") Image:@"喝水提醒" Action:Command_Water]];
        [s.items addObject:[self cModelWithTitle:SWString(@"吃药提醒") Image:@"吃药提醒" Action:Command_Medicine]];
        [s.items addObject:[self cModelWithTitle:SWString(@"生理期设置") Image:@"生理期设置" Action:Command_PhysiologicalPeriod]];
        [s.items addObject:[self cModelWithTitle:SWString(@"定时体温设置") Image:@"定时体温设置" Action:Command_BodyTemperature]];
        
    }else {
        self.jy_title = SWString(@"其他功能设置");
        [s.items addObject:[self cModelWithTitle:SWString(@"勿扰设置") Image:@"勿扰设置" Action:Command_DoNotDisturb]];
        [s.items addObject:[self cModelWithTitle:SWString(@"消息通知") Image:@"消息通知" Action:Command_Notification]];
        [s.items addObject:[self cModelWithTitle:SWString(@"SOS设置") Image:@"SOS设置" Action:Command_SOS]];
        [s.items addObject:[self cModelWithTitle:SWString(@"查找手表") Image:@"查找手机" Action:Command_FindWatch]];
        [s.items addObject:[self cModelWithTitle:SWString(@"闹钟设置") Image:@"闹钟设置" Action:Command_Alarm]];
        [s.items addObject:[self cModelWithTitle:SWString(@"防丢设置") Image:@"防丢设置" Action:Command_Antilost]];
        [s.items addObject:[self cModelWithTitle:SWString(@"OTA升级") Image:@"OTA升级" Action:Command_OTA_Upgrade]];
    }
    self.dataSources = @[s];
    [self reloadIfNeeded];
}

- (NormalArrowModel *)cModelWithTitle:(NSString *)title Image:(NSString *)icon Action:(DeviceCommandEnum)action{
    NormalArrowModel * m = [NormalArrowModel createTitle:title size:CGSizeMake(kScreenWidth, 65) hiddenArrow:NO action:kMsgPackForward(@"clickCell:",WKProxy(self),  @(action))];
    m.icon = icon;
    return m;
}

- (void)clickCell:(NSNumber *)action {
    if (action.intValue == Command_Alarm) {
        ZHRunEngine(kRunCMDINFO(@"_show_AlarmListView",@{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_StepGoal || action.intValue == Command_ScreenTime) {
        ZHRunEngine(kRunCMDINFO(@"_show_StepTargetView",@{@"action":action,@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_Notification) {
        ZHRunEngine(kRunCMDINFO(@"_show_NotificationSetView", @{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_Sedentary || action.intValue == Command_HeartRateReminders || action.intValue == Command_RaiseHand|| action.intValue == Command_Water|| action.intValue == Command_Medicine||  action.intValue == Command_BodyTemperature) {
        ZHRunEngine(kRunCMDINFO(@"_show_HeartRateReminderView",@{@"uuid":self.uuid,@"action":action}), nil);
    }else if (action.intValue == Command_VibrationSet) {
        ZHRunEngine(kRunCMDINFO(@"_show_VibrationSetView",@{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_DoNotDisturb) {
        ZHRunEngine(kRunCMDINFO(@"_show_DoNotDisturbView",@{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_PhysiologicalPeriod) {
        ZHRunEngine(kRunCMDINFO(@"_show_PhysiologicalPeriodView",@{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_Antilost) {
        ZHRunEngine(kRunCMDINFO(@"_show_SwitchSet",@{@"uuid":self.uuid,@"action":action}), nil);
    }else if (action.intValue == Command_LanguageSet) {
        ZHRunEngine(kRunCMDINFO(@"_show_LanguageSelectView",@{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_SOS) {
        ZHRunEngine(kRunCMDINFO(@"_show_SOSSetView",@{@"uuid":self.uuid}), nil);
    }else if (action.intValue == Command_12_24_Set || action.intValue == Command_LengthSet || action.intValue == Command_TemperatureSet) {
        ZHRunEngine(kRunCMDINFO(@"_show_HoursSetView",@{@"uuid":self.uuid,@"action":action}), nil);
    }else if(action.intValue == Command_FindWatch) {
        [[WatchCommandTool sharedInstance] writeStormCommand:Command_FindWatch ToPeripheral:self.peripheral Value:@[] reBack:^(NSString * _Nonnull backData) {
            
        }];
        toast(@"已发送");
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
